#include <iostream>
#include <string>
using namespace std;
class CID {
private:
    int *weight_array;
    int n;  //weight_array数组的长度
    char *check_code ;
    int m; //check_code数组的长度
    string old_card_id;
    string new_card_id;
public:
    CID(int weight_array1[], int n1, char check_code1[], int m1) {
        weight_array = weight_array1; //直接赋值地址即可
        check_code = check_code1;
       
        n = n1;
        m = m1;
    }
    void print() {
        cout << "Origin ID number:   " << old_card_id << endl;
        cout << "extended ID number: " << new_card_id << endl;
    }
    void extend_old_id(string old_card_id1) {
        old_card_id = old_card_id1;
        //插入19
        
        string left = old_card_id.substr(0, 6);
        string right = old_card_id.substr(6);
        string extended_17_id = left + "19" + right;



        char * p=(char*)extended_17_id.data();
        int s = 0;
        for (int i = 0; i < 17; i++) {
            s += weight_array[i] * (p[i] - '0');
        }
        int y = s % 11;
        
        char code = check_code[y];

        //把一个char字符转化为string
        char tmp[2];
        tmp[0] = code;
        tmp[1] = '\0';
        string code1 = tmp;
        new_card_id = extended_17_id + code1;

    }

};

int main() {

    int weight_array [17] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
    char check_code [11] = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
    
    string old_card_id = "340524800101001";

    CID cid(weight_array, 17, check_code, 11);

    cid.extend_old_id(old_card_id);
    cid.print();

    return 0;
}
